<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
	Object obj = request.getSession().getAttribute("role_resource");
	if (null == obj) {
		response.setStatus(1000);
		return;
	}
%>
<style type="text/css">
.complete .x-tree-node-anchor span {
	text-decoration: line-through;
	color: #777;
}
</style>
<script type="text/javascript">
//城市树数据源
var tree_store = new Ext.data.JsonStore( {
	root : "data",
	totalProperty : "total",
	fields : [ "id", "text", "leaf" ],
	url : "tree!city.action"
});
//计费列表数据源
var data_store = new Ext.data.JsonStore(
		{
			root : "data",
			totalProperty : "total",
			fields : [ "epibolyno", "cityno", "envelop", "reckoning", "print",
					"envcost", "envlopweight", "totalweight", "epibolyname",
					"cityname", "deliver" ],
			url : "costPar!list.action"
		});
//外包商下拉列表
var epiboly_store = new Ext.data.JsonStore( {
	root : "data",
	fields : [ "id", "name" ],
	url : "epiboly!listAll.action"
});

epiboly_store.load();
var updateWin;
//定义数据显示面板
var p1 = {
	id : "p1",
	region : "center",
	xtype : "editorgrid",
	stripeRows : true,
	loadMask : true,//在加载数据时遮罩住元素,替换元素Updater的加载提示器，并且在初始化加载之后销毁
	autoExpandColumn : "epibolyname",//自动填充
	autoExpandMin : 100,//自动填充最小宽度
	store : data_store,
	headersDisabled : true,
	columns : [ new Ext.grid.RowNumberer( {
		header : "序号",
		width : 50
	}), {
		header : "城市",
		dataIndex : "cityname",
		menuDisabled : true
	}, {
		header : "外包商名称",
		dataIndex : "epibolyname",
		id : "epibolyname",
		menuDisabled : true
	}, {
		header : "信封费用",
		dataIndex : "envelop",
		menuDisabled : true,
		editor : new Ext.grid.GridEditor(new Ext.form.NumberField( {
			allowBlank : false,
			maxValue : 9999999.999,
			decimalPrecision : 3,
			allowNegative : false
		}))
	}, {
		header : "账单印刷费",
		dataIndex : "reckoning",
		menuDisabled : true,
		editor : new Ext.grid.GridEditor(new Ext.form.NumberField( {
			allowNegative : false,
			maxValue : 9999999.999,
			decimalPrecision : 3,
			allowBlank : false
		}))
	}, {
		header : "账单打印费",
		dataIndex : "print",
		menuDisabled : true,
		editor : new Ext.grid.GridEditor(new Ext.form.NumberField( {
			allowNegative : false,
			maxValue : 9999999.999,
			decimalPrecision : 3,
			allowBlank : false
		}))
	}, {
		header : "封装费",
		dataIndex : "envcost",
		editor : new Ext.grid.GridEditor(new Ext.form.NumberField( {
			allowNegative : false,
			maxValue : 9999999.999,
			decimalPrecision : 3,
			allowBlank : false
		}))
	},{
		header : "投递费",
		dataIndex : "deliver",
		editor : new Ext.grid.GridEditor(new Ext.form.NumberField( {
			allowNegative : false,
			maxValue : 9999999.999,
			decimalPrecision : 3,
			allowBlank : false
		}))
	}, {
		header : "信封克重",
		dataIndex : "envlopweight",
		menuDisabled : true,
		editor : new Ext.grid.GridEditor(new Ext.form.NumberField( {
			allowNegative : false,
			maxValue : 100,
			decimalPrecision : 0,
			allowBlank : false
		}))
	}, {
		header : "总克重",
		id : "totalweight",
		dataIndex : "totalweight",
		menuDisabled : true,
		editor : new Ext.grid.GridEditor(new Ext.form.NumberField( {
			allowNegative : false,
			maxValue : 100,
			decimalPrecision : 0,
			allowBlank : false
		}))
	} ],
	buttonAlign : "center",
	buttons : [ {
		text : "批量修改",
		id : "batchUpdate",
		xtype : "button",
		handler : function() {
			if (!updateWin) {
				updateWin = new Ext.Window(
						{
							layout : "fit",
							width : 700,
							height : 600,
							closeAction : "hide",
							plain : true,
							items : {
								frame : true,
								labelAlign : 'left',
								id : 'updateFrom',
								bodyStyle : 'padding:5px',
								xtype : 'form',
								layout : 'column',
								items : [
										{
											columnWidth : 0.40,
											items : {
												title : '更新城市',
												id : 'updateCity',
												width : 250,
												height : 510,
												autoScroll : true,
												animate :false,
												rootVisible : false,
												xtype : "treepanel"
												,checkModel: 'cascade'   //对树的级联多选   
												,onlyLeafCheckable: false//对树所有结点都可选   
												,root : new Ext.tree.AsyncTreeNode(
												{
													id : "root"
												}),
												loader: new Ext.tree.TreeLoader({
													url:"treeCheck!city.action"
											        ,baseAttrs:{uiProvider:Ext.ux.TreeCheckNodeUI} //添加 uiProvider 属性   
											    })
											}
										},
										{
											columnWidth : 0.6,
											xtype : 'fieldset',
											labelWidth : 90,
											title : '外包商计费信息',
											defaults : {
												width : 260,
												border : false
											},
											defaultType : 'textfield',
											autoHeight : true,
											bodyStyle : Ext.isIE ? 'padding:0 0 5px 15px;'
													: 'padding:10px 15px;',
											border : false,
											style : {
												"margin-left" : "10px",
												"margin-right" : Ext.isIE6 ? (Ext.isStrict ? "-10px"
														: "-13px")
														: "0"
											},
											items : [ {
												fieldLabel : "外包商名称",
												allowBlank : false,
												id : 'epibolyno',
												name : 'epibolyno',
												xtype : "billCombox",
												store : epiboly_store,
												valueField : "id",
												displayField : "name"
											}, {
												fieldLabel : "信封费用",
												name : 'costPar.envelop',
												xtype : 'numberfield',
												maxValue : 9999999.999,
												decimalPrecision : 3,
												value : 0,
												allowBlank : false,
												allowNegative : false
											}, {
												fieldLabel : "账单印刷费",
												name : 'costPar.reckoning',
												xtype : 'numberfield',
												allowNegative : false,
												maxValue : 9999999.999,
												decimalPrecision : 3,
												value : 0,
												allowBlank : false
											}, {
												fieldLabel : "账单打印费",
												name : 'costPar.print',
												xtype : 'numberfield',
												value : 0,
												allowNegative : false,
												allowBlank : false
											}, {
												fieldLabel : "封装费",
												name : 'costPar.envcost',
												xtype : 'numberfield',
												maxValue : 9999999.999,
												decimalPrecision : 3,
												value : 0,
												allowNegative : false,
												allowBlank : false
											},{
												fieldLabel : "投递费",
												name : 'costPar.deliver',
												xtype : 'numberfield',
												maxValue : 9999999.999,
												decimalPrecision : 3,
												value : 0,
												allowNegative : false,
												allowBlank : false
											}, {
												fieldLabel : "信封克重",
												name : 'costPar.envlopweight',
												xtype : 'numberfield',
												maxValue : 100,
												value : 0,
												allowNegative : false,
												decimalPrecision : 0,
												allowBlank : false
											}, {
												fieldLabel : "总克重",
												name : 'costPar.totalweight',
												xtype : 'numberfield',
												maxValue : 100,
												value : 0,
												allowNegative : false,
												decimalPrecision : 0,
												allowBlank : false
											} ]
										} ]
							},
							buttons : [
									{
										text : "确认",
										handler : function() {
											var ids = '', selNodes = Ext
													.getCmp("updateCity")
													.getChecked();
											if (selNodes.length == 0) {
												Ext.Msg
														.show( {
															title : "提示",
															msg : "请选择更新城市!",
															buttons : Ext.Msg.OK,
															animEl : "elId",
															icon : Ext.MessageBox.WARNING
														});
												return;
											}
											Ext.each(selNodes, function(node) {
												if (node.isLeaf()) {
													if (ids.length > 0) {
														ids += ',';
													}
													ids += node.id;
												}
											});

											if (Ext.getCmp("updateFrom").getForm().isValid()) {
												Ext.getCmp("updateFrom").getForm().submit({
													url : 'costPar!battchUpdate.action',
													params : {
														'costPar.cityno' : ids,
														'costPar.epibolyno' : Ext.getCmp('epibolyno').getValue()
													},
													waitMsg : '正在提交数据...',
													success : function(fp,o) {
														Ext.Msg.show({
															title : "提示",
															msg : "一共更新"
																	+ o.result.total
																	+ "条数据！",
															buttons : Ext.Msg.OK,
															icon : Ext.MessageBox.INFO
														});
														updateWin.hide();
													}
												});
											}
										}
									}, {
										text : "关闭",
										handler : function() {
											updateWin.hide();
										}
									} ]
						});
			} else {
				Ext.getCmp("updateCity").getRootNode().reload();
				Ext.getCmp("updateFrom").getForm().reset();
			}
			updateWin.show(this);
		}
	} ],
	bbar : new Ext.ux.PagingToolbar( {
		pageSize : 21,
		store : data_store
	}),
	listeners : {
		"validateedit" : function(e) {
			var para = e.field;
			var da = {
				"costPar.epibolyno" : e.record.data["epibolyno"],
				"costPar.cityno" : e.record.data["cityno"],
				"costPar.envelop" : e.record.data["envelop"],
				"costPar.reckoning" : e.record.data["reckoning"],
				"costPar.print" : e.record.data["print"],
				"costPar.envcost" : e.record.data["envcost"],
				"costPar.deliver" : e.record.data["deliver"],
				"costPar.envlopweight" : e.record.data["envlopweight"],
				"costPar.totalweight" : e.record.data["totalweight"]
			};
			da["costPar." + para] = e.value;
			Ext.Msg.confirm("警告","是否确定将 "+e.record.data.epibolyname+"（"+e.record.data.cityname+"） 的【"+e.grid.colModel.getColumnHeader(e.column)+"】由 "+e.originalValue+" 改为 "+e.value+" ？", function(btn){
			    if(btn == "yes") {
			    	var result = Ext.Ajax.request( {
						clientValidation : true,
						params : da,
						url : "costPar!upd.action",
						success : function(response, opts) {
							var d = eval("(" + response.responseText + ")");
							Ext.getCmp("p1").getBottomToolbar().doRefresh();
							if (d.code == "0") {
								Ext.Msg.alert("警告","操作成功！");
							} else {
								Ext.Msg.alert("警告","操作失败！");
							}
						}
					});
		    	} else {
		    		Ext.getCmp("p1").getBottomToolbar().doRefresh();
		    	}
			});
		}
	}
};

var costpar_pel = new Ext.Panel(
		{
			layout : "border",
			border : false,
			items : [
					{
						id : "cityTree",
						xtype : "billTreePanel",
						dataUrl : "tree!city.action",
						autoScroll : true,
						root : new Ext.tree.AsyncTreeNode( {
							id : "root",
							expanded : true
						// 自动展开节点
								}),
						listeners : {
							"click" : function(node) {
								if (node.isLeaf()) {
									data_store.baseParams = data_store.baseParams
											|| {};
									data_store.baseParams["costPar.cityno"] = node.attributes.id;
									data_store.load( {
										params : {
											start : 0,
											limit : 21
										}
									});
								}
							}
						}
					}, p1 ]
		});
data_store.load();

var CenterPanel = Ext.getCmp("CenterPanel");
CenterPanel.removeAll();
CenterPanel.add(costpar_pel);
CenterPanel.doLayout();
</script>
